package com.lagou.edu.minicat;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 启动minicat，客户端一旦连接，返回hello，minicat
 *
 * @author gaoguangyang
 */
public class BootstrapV1 {

    private int port = 8080;

    public void start() throws IOException {
        ServerSocket serverSocket = new ServerSocket(port);
        while (true) {
            Socket accept = serverSocket.accept();
            String content = "<h1>Hello, Minicat.</h1>";
            OutputStream outputStream = accept.getOutputStream();
            outputStream.write(ProtocolHttpUtil.http200header(content.getBytes().length).getBytes());
            outputStream.write(content.getBytes());
            accept.close();
        }
    }

    public static void main(String[] args) throws Exception {
        BootstrapV1 bootstrapV1 = new BootstrapV1();
        bootstrapV1.start();
    }
}
